package utils;

import java.io.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ReadTextFile {


    class Math implements Runnable {
        public int time = 0;
        public boolean flag = true;

        @Override
        public void run() {
            long stat = System.currentTimeMillis();
            BigDecimal num = BigDecimal.valueOf(1.01);
            for (int i = 0; i <= 30; i++) {
                time = i;
                num = num.multiply(num);
                System.out.println("第" + (i + 1) + "次，用时:" + formatDuring(System.currentTimeMillis() - stat) + ",结果:" + num.toEngineeringString());
                System.out.println(num);
            }

            System.out.println("time:" + (System.currentTimeMillis() - stat));
            flag = false;
        }
    }

    public static String formatDuring(long mss) {

        long days = mss / (1000 * 60 * 60 * 24);

        long hours = (mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
        long minutes = (mss % (1000 * 60 * 60)) / (1000 * 60);
        long seconds = (mss % (1000 * 60)) / 1000;
        return days + "天" + hours + "时" + minutes + "分"+seconds+"秒";
    }


    public static String msg = "mobilesAndNames=[{\"mobile\":\"189 1059 4517\",\"name\":\"appcan\"},{\"mobile\":\"15946018189\",\"name\":\"爸\"},{\"mobile\":\"189 1141 5096\",\"name\":\"白佳璐\"},{\"mobile\":\"18178919596\",\"name\":\"程期星\"},{\"mobile\":\"15764651071\",\"name\":\"迟旭\"},{\"mobile\":\"15846094047\",\"name\":\"大爷\"},{\"mobile\":\"15901071828\",\"name\":\"德林室友\"},{\"mobile\":\"18746391402\",\"name\":\"二舅\"},{\"mobile\":\"+8618500079596\",\"name\":\"高梦颖\"},{\"mobile\":\"185 1145 1596\",\"name\":\"哥\"},{\"mobile\":\"186 6562 2419\",\"name\":\"哥\"},{\"mobile\":\"188 1012 8542\",\"name\":\"哥\"},{\"mobile\":\"18845287545\",\"name\":\"郭瑞婷\"},{\"mobile\":\"15901151996\",\"name\":\"侯冬雪\"},{\"mobile\":\"137 1828 6685\",\"name\":\"胡浩\"},{\"mobile\":\"15611123320\",\"name\":\"姬涛涛\"},{\"mobile\":\"18612003624\",\"name\":\"纪宏远\"},{\"mobile\":\"18515391871\",\"name\":\"季铭欣\"},{\"mobile\":\"+8618560276388\",\"name\":\"孔宪波\"},{\"mobile\":\"185 0102 0618\",\"name\":\"刘卫民\"},{\"mobile\":\"+8613945128623\",\"name\":\"妈\"},{\"mobile\":\"15636822016\",\"name\":\"妈\"},{\"mobile\":\"18519014101\",\"name\":\"马竞超\"},{\"mobile\":\"13501380564\",\"name\":\"马晓微\"},{\"mobile\":\"15718890288\",\"name\":\"牛亚运\"},{\"mobile\":\"13260205295\",\"name\":\"邱爽\"},{\"mobile\":\"15236391063\",\"name\":\"三叔\"},{\"mobile\":\"130 5161 8615\",\"name\":\"史宏阳\"},{\"mobile\":\"136 8112 1964\",\"name\":\"首汽约车hr\"},{\"mobile\":\"188 0337 6959\",\"name\":\"四叔\"},{\"mobile\":\"15945238298\",\"name\":\"王教练\"},{\"mobile\":\"13311188070\",\"name\":\"王禄中\"},{\"mobile\":\"189 1140 7983\",\"name\":\"王森\"},{\"mobile\":\"15146216427\",\"name\":\"王山\"},{\"mobile\":\"15801444129\",\"name\":\"小鑫鑫\"},{\"mobile\":\"13206742360\",\"name\":\"徐群\"},{\"mobile\":\"136 7110 4846\",\"name\":\"许姗姗\"},{\"mobile\":\"158 0112 1770\",\"name\":\"许姗姗\"},{\"mobile\":\"188 1051 1803\",\"name\":\"杨欣\"},{\"mobile\":\"15841085262\",\"name\":\"张昊\"},{\"mobile\":\"18513294978\",\"name\":\"张昊\"},{\"mobile\":\"135 2101 1963\",\"name\":\"张朋\"},{\"mobile\":\"13821910502\",\"name\":\"周金\"},{\"mobile\":\"18510075297\",\"name\":\"周开业\"},{\"mobile\":\"176 1077 9727\",\"name\":\"周赢\"},{\"mobile\":\"15004544596\",\"name\":\"朱莉\"},{\"mobile\":\"13521781425\",\"name\":\"宗虎\"}]";

    private static Map<String, Double> readFile(String path) {
        try {
            BufferedReader bufferedReader = new BufferedReader(new FileReader(new File(path)));
            StringBuffer sql = new StringBuffer("insert into `COMPANY`.`company_use_office_card` ( `phone`, `card_no`, `discount_rata`, `type`, `status`, `create_time`, `update_time`) values");
            // ;
            int sum = 0;
            while (true) {
                String s = bufferedReader.readLine();
                if (s == null)
                    break;
                System.out.println(s);
                sql.append("( '" + s + "', '" + s + "', '0.78', '0', '1', now(), now() ), ");
                sum++;
            }
            System.out.println(sum);
            System.out.println(sql);
            return null;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    private static Map<String, Double> readFile2(String path) {
        try {
            BufferedReader bufferedReader = new BufferedReader(new FileReader(new File(path)));
            List<String> list = new ArrayList<>();
            List<String> quChongList = new ArrayList<>();
            int sum = 0;
            int quChong = 0;
            while (true) {
                String s = bufferedReader.readLine();
                if (s == null)
                    break;
                if(!list.contains(s)) {
                    list.add(s);
                    quChong++;
                } else {
                    quChongList.add(s);
                }
                sum++;
            }
            System.out.println("总数量:" + sum + ",,,去重后数量" + quChong);
            System.out.println("重复订单号:" + quChongList);
            return null;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 拼接更新数据sql
     * @param path
     * @return
     */
    private static Map<String, Double> readFile3(String path) {
        try {
            String tempSql = "update `company_department` set `sort`= xxxxx where  id = xxxxx;";
            StringBuffer sql = new StringBuffer();
            BufferedReader bufferedReader = new BufferedReader(new FileReader(new File(path)));
            int sum = 0;
            while (true) {
                String s = bufferedReader.readLine();
                if (s == null)
                    break;
                sql.append(tempSql.replace("xxxxx", s));
                sum++;
            }
            System.out.println(sql);
            System.out.println("总数:" + sum);
            return null;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }


    private static Map<String, Double> readFileToJson(String path) {
        try {
            BufferedReader bufferedReader = new BufferedReader(new FileReader(new File(path)));
            StringBuffer sql = new StringBuffer("insert into `COMPANY`.`company_use_office_card` ( `phone`, `card_no`, `discount_rata`, `type`, `status`, `create_time`, `update_time`) values");
            // ;
            int sum = 0;
            while (true) {
                String s = bufferedReader.readLine();
                if (s == null)
                    break;
                System.out.println(s);
                sql.append("( '" + s + "', '" + s + "', '0.78', '0', '1', now(), now() ), ");
                sum++;
            }
            System.out.println(sum);
            System.out.println(sql);
            return null;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) throws InterruptedException {
        readFileToJson("/Users/lipengxiang/Desktop/不良信息受理-29-13号所有入参.txt");


//        Math math = new ReadTextFile().new Math();
//        Thread t1 = new Thread(math);
//        t1.start();
//        long stat = System.currentTimeMillis();
//        while (true) {
//            if (!t1.isAlive()) {
//                break;
//            }
//            System.out.println("这是第" + (math.time + 1) + "次计算,用时：" + formatDuring(System.currentTimeMillis() - stat));
//            Thread.sleep(1000);
//        }

    }
}
